<!DOCTYPE html>
<html>
<head>
    <title>$app.topic tag配置</title>
    #parse("/inc/meta.htm")
</head>
<body id="inner_page_start">
<div class="modal fade" id="ex-back-big" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <form action="/other/tagInfo" type="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title h4" id="myExtraLargeModalLabel">tag 配置</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">

                    <input type="hidden" name="id" id="menu-id">
                    <div class="form-group row">
                        <div class="col-sm-2"></div>
                        <label for="menu-name" class="col-form-label col-sm-2">tag名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="menu-name" name="name" required/></div>
                    </div>
                    <div class="form-group  row">
                        <div class="col-sm-2"></div>
                        <label for="menu-value" class="col-form-label col-sm-2">tag 值</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="menu-value" name="value" required/></div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-2"></div>
                        <label for="menu-type" class="col-form-label col-sm-2">tag类型</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="menu-type" name="type" required/></div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-2"></div>
                        <label for="menu-des" class="col-form-label col-sm-2">tag类型名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="menu-des" name="des" required/></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" id="sub-button-tag">新建</button>
                </div>
            </div>
        </form>
    </div>
</div>
#parse("/inc/header.htm")
<div id="wrapper">
    #parse("/inc/menu.htm")
    <div id="content-wrapper">
        <div class="container-fluid">
            <!-- 面包屑-->
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    其他管理
                </li>
                <li class="breadcrumb-item active">标签字段</li>
            </ol>
        </div>
        <!-- /.container-fluid class="card mb-3"-->
        <div class="container-fluid">
            <div class="card-body">
                    <div class="form-inline">
                        <div class="form-group mx-sm-3">
                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ex-back-big" >
                                新建菜单</button>
                        </div>
                    </div>
                    <br/>

                    <div class="row">
                        <div class="col-sm-12 table-outer-box">
                            <table class="table table-bordered dataTable" id="dataTable" width="100%" cellspacing="0" role="grid" aria-describedby="dataTable_info" style="width: 100%;">
                                <thead>
                                <tr role="row">
                                    <th>名称</th>
                                    <th>值</th>
                                    <th>类型ID</th>
                                    <th>类型名称</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                #foreach( $parent in $respData )
                                <tr #if($tag == $parent.id) style="background: #0bb20c" #end>
                                    <td>$!parent.name</td>
                                    <td>$!parent.value</td>
                                    <td>$!parent.type</td>
                                    <td>$!parent.des</td>
                                    <td>
                                        <button type="button" class="btn btn-primary btn-sm"  data-toggle="modal" data-target="#ex-back-big"
                                                data-tid="$!parent.id">编辑</button>
                                    </td>
                                </tr>
                                #end
                                </tbody>
                            </table>
                        </div>
                    </div>
            </div>
        </div>
        #parse("/inc/copyright.htm")
    </div>
    <!-- /.content-wrapper -->
</div>
#parse("/inc/footer.htm")
<script>
    $('#sub-button-tag').on('submit',function(){
        var a = $("#menu-name").val()
        if(!a) {
            showError("名称") ;
            return false
        }
        a = $("#menu-value").val()
        if(!a) {
            showError("值") ;
            return false
        }
        a = $("#menu-type").val()
        if(!a) {
            showError("类型") ;
            return false
        }
        a = $("#menu-des").val()
        if(!a) {
            showError("类型名称") ;
            return false
        }
    })

    function showError(str){
        // show str
    }

    $('#ex-back-big').on('show.bs.modal', function (event) {
        $("#menu-name").val("")
        $("#menu-value").val("")
        $("#menu-type").val("")
        $("#menu-des").val("")
        $("#menu-id").val("")
        $("#sub-button-tag").text("新建")

        var button = $(event.relatedTarget)
        var tid = button.data('tid')
        if(tid){
            $("#menu-id").val(tid)
            $("#sub-button-tag").text("更新")
            tag(tid)
        }
    })

    function tag(mid){
        if(!mid)
            mid = ""
        var good = false
        $.ajax({
            url: "/other/tag",
            data: { id:mid },
            type: "POST",
            dataType: "json",
            async: false,
            success: function(data) {
                if(data.state == "000"){
                    good = true
                    $("#menu-name").val(data.data.name)
                    $("#menu-value").val(data.data.value)
                    $("#menu-type").val(data.data.type)
                    $("#menu-des").val(data.data.des)
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("网络异常，请稍后重试"+textStatus)
                setTimeout(function(){
                    $("#ex-back-big").modal("hide")
                },500);
            }
        });
        return good
    }
</script>
</body>
</html>